home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 09, No. 10 (1988-10)(MicroSPARC)(Side A).zip / Nibble Volume 09, No. 10 (1988-10)(MicroSPARC)(Side A).po / AUA.S < prev    next >
Text File  |  1996-12-24  |  14KB  |  383 lines

  1. *                     AUA Source Code                     *
  2. *                   by Dean M. Pickering                  *
  3. *                    Copyright (C) 1988                   *
  4. *                    by MicroSPARC, Inc                   *
  5. *                    Concord, MA  01742                   *
  6. *                                                         *
  7. *                 Assembler:  EDASM.SYSTEM                *
  8. *
  9. * The code is relocatable and may be attached to the end of
  10. * BASIC programs to avoid reserving space.
  11. MAIN      EQU $06 Main width before point
  12. DEC       EQU $07 No.of decimal places
  13. LENGTH    EQU $08 LEN of digit string
  14. COMMAS    EQU $09 Commas flag
  15. DOLLAR    EQU $18 Flag for dollar sign
  16. PROMPT    EQU $33 Prompt character held here
  17. VARADDR   EQU $85 Addr of var to be moved
  18. BASEND    EQU $AF BASIC load end is in $AF,B0
  19. CHARGET   EQU $B1 BASIC input - get next char
  20. CHARGOT   EQU $B7 BASIC input - get curr. char
  21. ERRFLAG   EQU $D8 Neg if ONERR active
  22. STACK     EQU $DF Stack pointer saved here
  23. SAVEFLAG  EQU $E3 Temporary for error flag
  24. AMPER     EQU $03F5 Ampersand jump vector
  25. *   Use lots of ROM subroutines - saves code
  26. FNDLN     EQU $D61A Get addr of Line in $50,51
  27. CLRHIGH   EQU $D539 Strip high bits in inp buffer
  28. RESTART   EQU $D7D2 Re-start prog after error
  29. LINEADDR  EQU $D941 Set $B8,B9 to line in $50,51
  30. UNDEFD    EQU $D97C UNDEF'D ERROR exit
  31. SKIP      EQU $D995 Move $B8,9 to next colon/null
  32. ADDON     EQU $D998 Add Y to pointer $B8,B9
  33. MOVEPTR   EQU $DA9A Instal ptr in var in $85,86
  34. PRINTCR   EQU $DAFB Print carriage return
  35. PRINTSTR  EQU $DB3A Print string from Y,A to null
  36. PRINTA    EQU $DB5C Print accumulator
  37. EVAL      EQU $DD67 Eval input into FP reg (FP1)
  38. CONFMSTR  EQU $DD6C Confirm variable is string
  39. COMMA     EQU $DEBE Confirm comma next
  40. CHECKA    EQU $DEC0 Confirm next = Acc
  41. SYNTAX    EQU $DEC9 SYNTAX ERROR exit
  42. FINDVAR   EQU $DFE3 Address of variable into Y,A
  43. POINTER   EQU $E3E7 Establ. str ptr in ZP stack
  44. MOVESTR   EQU $E3E9 Move str to string space
  45. LENA      EQU $E600 Pop ZP stack, LEN in Acc
  46. GETX1     EQU $E6F8 Evaluate input into X
  47. GETX2     EQU $E74C Check comma, eval inp into X
  48. CONVBIN   EQU $E752 Convert FP1 to bin in $50,51
  49. ADD       EQU $E7BE Add val at Y,A to FP1
  50. MULT      EQU $E97F Mult FP1 by val at Y,A
  51. SIGN      EQU $EB82 Get sign of FP1 (FF,0, or 1)
  52. ABS       EQU $EBAF Convert FP1 val to ABS
  53. COMP      EQU $EBB2 Compare FP1 with val at Y,A
  54. INT       EQU $EC23 Convert FP1 to INT
  55. STR       EQU $ED34 Make STR$(FP1) at $0100
  56. PRBL2     EQU $F94A MONITOR - print X blanks
  57. GETLN1    EQU $FD6F Get input str in input buffer
  58. BELL      EQU $FF3A MONITOR - ring bell
  59. *
  60.           ORG $2000 Arbitrary, relocatable.
  61. *
  62. * Identify keyword and confirm validity
  63. *
  64. START     LDA ERRFLAG Save ONERR flag. It may be
  65.           STA SAVEFLAG  on or off
  66.           CLC Turn off ONERR to trap errors
  67.           ROR ERRFLAG  in these routines
  68.           JSR CHARGOT Get current char after "&"
  69.           CMP #$84 Is it INPUT token?
  70.           BEQ INPUT Yes - jump and process it
  71.           CMP #$AE Is it RESTORE token?
  72.           BEQ RESTORE Yes - process
  73.           CMP #$A6 Is it RESUME token?
  74.           BEQ RESUME Yes - process
  75.           CMP #$BA Is it PRINT token?
  76.           BEQ USING1 Yes - process
  77. ERROR     JMP SYNTAX Not recognised - error exit
  78. *
  79. * Process & INPUT <str.var>
  80. *
  81. INPUT     JSR CHARGET Skip INPUT token
  82.           JSR FINDVAR Addr of input var into Y,A
  83.           JSR CONFMSTR SYNTAX ERR if not str var
  84.           STA VARADDR Save address for JSR MOVEPTR
  85.           STY VARADDR+1  later
  86.           LDX #$80 Tell BAS.SYS not to send C/R
  87.           STX PROMPT  to screen if input from file
  88.           LDA SAVEFLAG Restore ONERR flag to entry
  89.           STA ERRFLAG  state
  90.           JSR GETLN1 Assemble str in inp buffer
  91.           JSR CLRHIGH Strip high bits, add end zero
  92.           TAX X=0 (term chr in JSR MOVEPTR)
  93.           INY Y,A=$0200, start of string
  94.           JSR MOVESTR Move str to bot of str space,
  95.           JSR MOVEPTR  move ptr to var in $85,86
  96.           RTS Return to BASIC
  97. *
  98. * Process & RESTORE <expression>
  99. *
  100. RESTORE   JSR CHARGET Advance $B8,B9 to next char
  101.           LDA #$AB $AB is the token for GOTO
  102.           JSR CHECKA Confirm that GOTO follows
  103.           JSR EVAL Evaluate line No. into FP1
  104.           JSR CONVBIN Move No. from FP1 to $50,51
  105.           JSR FNDLN Get line address in $9B,9C
  106.           BCS LINEOK C=1 if line exists
  107.           JMP UNDEFD No, exit "UNDEF'D STATEMENT"
  108. LINEOK    LDY $9C Get line address from $9B,9C
  109.           LDX $9B  and deduct 1 to obtain the
  110.           BNE DECLOW  address of the zero byte
  111.           DEY  preceding the new line
  112. DECLOW    DEX 
  113.           STX $7D Move address to $7D,7E
  114.           STY $7E  (next data to be read)
  115.           LDA SAVEFLAG Restore ONERR flag to entry
  116.           STA ERRFLAG  state
  117.           RTS Return to BASIC
  118. USING1    BEQ USING Branch range extender
  119. *
  120. * First keyword was RESUME.  Was it NEXT or GOTO?
  121. *
  122. RESUME    JSR CHARGET Get next prog character
  123.           CMP #$82 Is it NEXT?
  124.           BEQ NEXT Branch if it is
  125.           CMP #$AB Is it GOTO?
  126.           BNE ERROR Crash if neither
  127. *
  128. * The statement was RESUME GOTO.
  129. *
  130. GOTO      LDX STACK Fix stack to pre-error
  131.           TXS
  132.           JSR CHARGET Advance pointer past token
  133.           JSR EVAL Eval linenum into FP reg
  134.           JSR CONVBIN Move it into $50,51
  135.           JSR LINEADDR Set $B8,B9 to start of line
  136.           BNE SETONERR Always (A= $B9)
  137. *
  138. * The statement was RESUME NEXT.
  139. *
  140. NEXT      LDA $DA Replace current line
  141.           STA $75  number with that of the
  142.           LDA $DB  line where the error
  143.           STA $76  occurred
  144.           LDA $DC Restore program pointer
  145.           STA $B8  to address of start of
  146.           LDA $DD  error statement
  147.           STA $B9
  148.           LDX $DF Restore stack to pre-error
  149.           TXS  condition
  150.           JSR CHARGOT Current char is colon or zero
  151.           BNE ADVANCE If zero, skip 4 line header
  152.           LDY #4  bytes before statement
  153.           JSR ADDON  (could be $00 or $3A)
  154. ADVANCE   JSR CHARGET Skip colon or zero
  155.           JSR SKIP Skip current (err) statement
  156. SETONERR  LDA SAVEFLAG Restore ONERR flag 
  157.           STA ERRFLAG  to entry condition
  158.           JMP RESTART Resume execution
  159. *
  160. * Process & PRINT [$] [,] M,D,<expression>
  161. *
  162. USING     LDA #00
  163.           STA COMMAS Initialise comma flag
  164.           STA DOLLAR  and dollar flag
  165.           JSR CHARGET Advance $B8,B9 past PRINT
  166.           CMP #$24 Is it a "$" sign?
  167.           BNE CHKCOM No, try for a comma
  168.           STA DOLLAR Set dollar flag
  169.           JSR CHARGET  and move on to next char
  170. CHKCOM    CMP #$2C Is it a thousand comma?
  171.           BNE NOCOMMA No commas
  172.           DEC COMMAS Set comma flag to #$FF
  173.           JSR CHARGET  and move on to next char
  174. NOCOMMA   JSR GETX1 Get M into X (Main width)
  175.           STX MAIN Save M in $06
  176.           JSR GETX2 Confirm comma, get D in X
  177.           STX DEC Save No.dec digits in $07
  178.           JSR COMMA Confirm comma next
  179. GETVAL    JSR EVAL Get val to print, in FP1
  180.           LDX DEC Get D
  181. LOOP1     DEX Decrement D until
  182.           BMI ROUND  negative
  183.           TXA  and save
  184.           PHA  current value
  185.           LDA #$50 $EA50 is address of
  186.           LDY #$EA  constant 10 decimal
  187.           JSR MULT Mult FP1 by 10, D times
  188.           PLA Recover current val
  189.           TAX
  190.           BPL LOOP1 Repeat (always)
  191. ROUND     JSR SIGN Get sign of FP1 in Acc
  192.           PHA Save it
  193.           JSR ABS Convert FP1 to ABS val
  194.           LDA #$64 $EE64 is address of
  195.           LDY #$EE  constant 0.5
  196.           JSR ADD Add 0.5 for rounding
  197.           JSR INT Convert FP1 to its INT
  198.           LDA #$0F $ED0F is address of
  199.           LDY #$ED  constant 999999999
  200.           JSR COMP Comp FP1 with limit in Y,A
  201.           BEQ STRING OK if Acc is -1 or 0
  202.           BPL OVERFL1 Overflow if Acc =1
  203. *
  204. *   Right shift and add leading zeros if value less than 1
  205. *
  206. STRING    JSR STR STR$(FP1) starting at $0100
  207.           JSR POINTER Establ pointer in ZP stack
  208.           JSR LENA Pop stack, LEN in Acc
  209. ZEROS     TAY Save LEN (No. of digits)
  210.           TAX
  211.           DEX Deduct 1
  212.           CPX DEC Leading 0's needed if L-1<D
  213.           BGE PRSPACE Jump if none
  214. SHIFT     LDA $0100,Y Shift string (Y chars)
  215.           STA $0101,Y  to right
  216.           DEY Dec Y until neg.
  217.           BPL SHIFT Shift L chars + terminal 0
  218.           LDA #$30 Insert leading "0"
  219.           STA $0100  in 1st char position
  220.           INX LEN
  221.           INX LEN+1 for each zero added
  222.           TXA
  223.           BNE ZEROS Repeat (always)
  224. PRSPACE   STY LENGTH Final LEN in $08
  225. *
  226. * Find No. commas if wanted, store in $09 with high bit set
  227. *
  228.           BIT COMMAS Neg if commas wanted
  229.           BPL LEADBLK Jump if no commas
  230.           TYA Current length into A
  231.           SEC
  232.           SBC DEC A is No. of int digits
  233.           LDX #$80 Clear low bits initially
  234.           CMP #$4 One comma if 4 or more digs
  235.           BLT STORECOM None if less than 4 digits
  236.           INX $81 for 1 comma
  237.           CMP #$7 Another if 7 or more digits
  238.           BLT STORECOM No, only one comma
  239.           INX $82 for two commas
  240. STORECOM  STX COMMAS Set number of commas
  241. *
  242. *     Increment length in $08 for commas
  243. *
  244.           TXA Move it into A
  245.           AND #$0F Trim off neg bit
  246.           CLC
  247.           ADC LENGTH Add No. of commas to length
  248.           STA LENGTH  in $08
  249.           BNE LEADBLK Always
  250. GETVAL1   BNE GETVAL Branch range extender
  251. OVERFL1   BPL OVERFL2 Branch range extender
  252. *    Print leading blanks for padding
  253. *
  254. LEADBLK   LDA MAIN Get main width M
  255.           BEQ NOLEAD No lead blanks if M = 0
  256.           CLC
  257.           ADC DEC A=M+D
  258.           CLC Deduct extra 1 for sign
  259.           SBC LENGTH A=M+D-L-1
  260.           LDX DOLLAR Do we need a dollar sign?
  261.           BEQ NUMBLK No
  262.           SEC
  263.           SBC #1 Yes, 1 less blank
  264. NUMBLK    TAX X= No. of leading blanks
  265.           BEQ NOLEAD Jump if none
  266.           BMI OVERFLOW Overflow if negative No.
  267.           JSR PRBL2 Print X blanks
  268. *
  269. *     Print sign unless M = 0 and value positive
  270. *
  271. NOLEAD    LDY #$2D Minus sign
  272.           PLA Recover sign (-1,0 or 1)
  273.           BMI ADDSIGN Always printed if neg
  274.           LDY #$20 Substitute space if pos or 0
  275.           LDX MAIN Is M = 0?
  276.           BEQ PRTDOLL No sign space if M = 0
  277. ADDSIGN   TYA Print sign (- or space)
  278.           JSR PRINTA
  279. *
  280. *     Print dollar sign if requested
  281. *
  282. PRTDOLL   LDA DOLLAR Do we print a "$"?
  283.           BEQ DIGITS No
  284.           JSR PRINTA Yes
  285. *
  286. *     Print digits, commas and point where appropriate
  287. *
  288. DIGITS    LDA LENGTH Get L
  289.           SEC
  290.           SBC DEC LEN-D =No. int digs + commas
  291.           TAX Save in X
  292.           LDY #00
  293. PRINTM    CPX #8 Maybe comma at 8th position
  294.           BNE TRYFOUR  before dec point
  295.           LDA #$2 Will there be 2 commas?
  296.           AND COMMAS Yes if 2 bit present
  297.           BNE PRTCOM Print mil comma (X=8, $09=2)
  298. TRYFOUR   CPX #4 Try 4th position
  299.           BNE NEXTDIG No comma, get real digit
  300.           LDA #$3 Thousands comma if
  301.           AND COMMAS  X=4 and $09=1 or 2
  302.           BEQ NEXTDIG Jump if not
  303. PRTCOM    LDA #$2C Load a comma
  304.           BNE PRTCHAR Print it
  305. OVERFL2   BPL OVERFLOW Branch range extender
  306. GETVAL2   BNE GETVAL1 Branch range extender
  307. NEXTDIG   LDA $0100,Y Print main digits (and comms
  308.           INY  if specd) until Y = LEN-D
  309. PRTCHAR   JSR PRINTA Print digit or comma
  310.           DEX X is total number of chars
  311.           BNE PRINTM  before dec. point
  312.           LDA DEC No. dec digits
  313.           BEQ NEXTITEM Next item if no decimals
  314.           LDA #$2E  else print point
  315.           JSR PRINTA  after int digits
  316.           TYA A=low byte start of dec digs
  317.           LDY #$01 YA is start of dec digits
  318.           JSR PRINTSTR Prnt string from Y,A to null
  319. *
  320. *     Item printed - see if another follows
  321. *
  322. NEXTITEM  JSR CHARGOT Get char after item printed
  323.           BEQ YESCR Carriage return and exit if
  324.           CMP #$3A  null byte or colon
  325.           BEQ YESCR
  326.           LDA #$3B Semicolon
  327.           JSR CHECKA Confirm ";" else Syntax Err
  328.           JSR CHARGOT Get char after ";"
  329.           BEQ END Return without C/R if null
  330.           CMP #$3A  or colon after ";"
  331.           BEQ END
  332.           BNE GETVAL2 Else more values to print
  333. YESCR     JSR PRINTCR Print C/R
  334. END       LDA SAVEFLAG Restore ONERR flag to entry
  335.           STA ERRFLAG  state
  336.           RTS Return to BASIC
  337. *
  338. *  Overflow routine prints "O/F" and leading and trailing
  339. *  blanks to maintain spacing. If no decimal places were
  340. *  specified (D=0), then only "OF" is printed.
  341. *
  342. OVERFLOW  PLA Pull sign, discard
  343.           LDX MAIN Original M
  344.           DEX
  345.           DEX M-2 blanks to print
  346.           BEQ PRTO Jump if none
  347.           BMI PRTO Always O/F if M =1 (illegal)
  348.           JSR PRBL2 Print X blanks
  349. PRTO      LDA #$4F
  350.           JSR PRINTA Print "O"
  351.           LDX DEC No. decimals
  352.           BEQ PRTF Jump if none
  353.           LDA #$2F
  354.           JSR PRINTA Print "/"
  355. PRTF      LDA #$46
  356.           JSR PRINTA Print "F"
  357.           LDX DEC No. decimals
  358.           BEQ END2 Jump if none
  359.           JSR PRBL2  else fill with blanks
  360. END2      JSR BELL Blow the whistle
  361.           BNE NEXTITEM Get next item to print
  362. *
  363. * Initiating routine if code is attached to BASIC.
  364. *
  365. INIT      LDA #$4C Set ampersand vector at $03F5
  366.           STA AMPER  for jump to start
  367.           SEC Vector address is end of
  368.           LDA BASEND  BASIC program given by
  369.           SBC #>CODELEN  $AF,B0 minus the length
  370.           STA AMPER+1  of the appended code
  371.           LDA BASEND+1
  372.           SBC #<CODELEN
  373.           STA AMPER+2
  374.           RTS Vector setup complete
  375. DEDUCT    DFB LOADEND-INIT PEEK here to find INIT
  376. *
  377. * That is the end of the code.  The next two lines are
  378. * used by the assembler to calculate its length.
  379. *
  380. LOADEND   EQU * This point given by $AF,B0
  381. CODELEN   EQU LOADEND-START Total code length
  382.           LST OFF,NOA,NOV Kill the symbol table
  383.